<script type="text/javascript">	
	var industry_select = "<?=$industry_select;?>";
	var user_select = "<?=$user_select;?>";
	var country_select = "<?=$country_select;?>";
</script>

<h2><?=$company->company_name;?></h2>

<div class="block tabs spaces">
	<div class="hd">
		<ul>
			<li><a href="">Projects</a></li>
			<li><a href="">Contacts and Addresses</a></li>
			<li><a href="">Company Info and Setup</a></li>
    </ul>
    <div class="clear"></div>
	</div>
	<div class="bd">

		<div id="clientProjects">

			<h3>Active Jobs</h3>
				<table class="projects" cellpadding="0" cellspacing="0" border="0">
					<thead>
						<td class="title">Job Title</td>
						<td class="contact">Contact</td>
						<td class="status">Status</td>
					</thead>
					<tbody>
			<?php if ($activejobs): ?>
							<?php foreach($activejobs as $row => $job):?>
								<tr>
									<td><a href="<?=site_url('company/'.$company->company_name.'/'.$job->job_title);?>"><?=$job->job_title;?></a> <small><?=$job->job_number;?></small></td>
									<td><?=$job->primary_contact_firstname;?> <?=$job->primary_contact_surname;?></td>
									<td><?=ucfirst($job->job_status);?> <?php if ($job->cancelled):?><em>Cancelled</em><?php endif;?> <?php if ($job->archived):?><em>Archived</em><?php endif;?></td>
								</tr>
							<?php endforeach;?>
			<?php endif;?>

			<?php if ($proposedjobs): ?>
						<?php foreach($proposedjobs as $row => $job):?>
							<tr>
								<td><a href="<?=site_url('company/'.$company->company_name.'/'.$job->job_title);?>"><?=$job->job_title;?></a> <small><?=$job->job_number;?></small></td>
								<td><?=$job->primary_contact_firstname;?> <?=$job->primary_contact_surname;?></td>
							</tr>
						<?php endforeach;?>
			<?php endif;?>
			
			<?php if ($completedjobs): ?>
						<?php foreach($completedjobs as $row => $job):?>
							<tr>
								<td><a href="<?=site_url('company/'.$company->company_name.'/'.$job->job_title);?>"><?=$job->job_title;?></a> <small><?=$job->job_number;?></small></td>
								<td><?=$job->primary_contact_firstname;?> <?=$job->primary_contact_surname;?></td>
							</tr>
						<?php endforeach;?>
			<?php endif;?>
			</tbody>
		</table>


			<?php if ($archivedjobs && $permissions->seearchive): ?>
					<h3>Archived Jobs</h3>
					<table class="projects" cellpadding="0" cellspacing="0" border="0">
						<thead>
							<th class="title">Job Title</th>
							<th class="contact">Contact</th>
						</thead>
						<tbody>
						<?php foreach($archivedjobs as $row => $job):?>
							<tr class="<?php if($row % 2):?>odd<?php else:?>even<?php endif;?>">
								<td><a href="<?=site_url('company/'.$company->company_name.'/'.$job->job_title);?>"><?=$job->job_title;?></a> <small><?=$job->job_number;?></small></td>
								<td><?=$job->primary_contact_firstname;?> <?=$job->primary_contact_surname;?></td>
							</tr>
						<?php endforeach;?>
						</tbody>
					</table>	
			<?php endif;?>
</div></div></div>


<div class="block">
	<div class="hd">
		<h2>Contacts</h2>
	</div>
	<div class="bd">
			<p><?php if ($permissions->addcontact):?><a class="addnew create" href="">Add Blank Contact</a><?php endif;?></p>
			<?=$contactlist;?>
</div>
</div>

<div class="block">
	<div class="hd">
		<h2>Addresses</h2>
	</div>
	<div class="bd">
		<p><?php if ($permissions->addaddress):?><a class="addnew create" href="">Add Blank Address</a><?php endif;?></p>
	<?=$addresslist;?>
	</div>
</div>

</div></div></div>

<div id="sidebar" class="yui-b">
	
	<div class="block">
		<div class="hd">
			<h2>New Project</h2>
		</div>
		<div class="bd">
		<?php if ($permissions->addjob):?>
		<?=form_open('jobs/add', array('id' => '', 'class' => 'addjob') );?>
		<fieldset>
			<input class="hidden" type="hidden" name="companyid" id="companyid" value="<?=$company->id;?>" />

			<p><label class="">Job Title</label>
			<input type="text" name="job_title" id="job_title" value="" class="text" /></p>


			<p><label class="" for="job_number">Job Number</label>
			<input type="text" name="job_number" id="job_number" value="" class="text" /></p>

			<hr />

			<p><label class="checkbox">
				<input type="radio" name="job_status" value="live" id="job_status_live" checked="checked" class="checkbox" /> Live</label>

				<label class="checkbox">
				<input type="radio" name="job_status" value="proposed" id="job_status_proposed" class="checkbox" /> Proposed</label></p>

		</fieldset>

		<input type="submit" class="submit" name="submit" value="Add Job" class="button" />
		<?=form_close();?>
	<?php endif;?>
		</div>
	</div>


<?php if ($permissions->viewcompanydetails):?>
	<div class="block">
		<div class="hd">
			<h2>Company Details</h2>
		</div>
		<div class="bd">
			
			<p>
				<strong>Account Code</strong><br />
				<span class="<?php if ($permissions->editcompanydetails):?>edit_textinput<?php endif;?>" id="<?=$company->id;?>|company|account_code"><?=$company->account_code;?></span>
			</p>
			<p>
				<strong>Website</strong><br />
				<span class="<?php if ($permissions->editcompanydetails):?>edit_textinput<?php endif;?>" id="<?=$company->id;?>|company|website"><?=$company->website;?></span>
			</p>
			<p>
				<strong>Industry</strong><br />
				<span class="<?php if ($permissions->editcompanydetails):?>edit_industry<?php endif;?>" id="<?=$company->id;?>|company|industryid|industry|industryname"><?=$company->industryname;?></span>
			</p>
			<p>
				<strong>Account Manager</strong><br />
				<span class="<?php if ($permissions->editcompanydetails):?>edit_userselect<?php endif;?>" id="<?=$company->id;?>|company|account_ownerid"><?php if (strlen($company->account_owner_firstname) || strlen($company->account_owner_lastname)):?><?=$company->account_owner_firstname;?> <?=$company->account_owner_lastname;?><?php else:?>None assigned<?php endif;?></span>
			</p>
			<p>
				<strong>Notes</strong><br />
				<span class="<?php if ($permissions->editcompanydetails):?>edit_textarea<?php endif;?>" id="<?=$company->id;?>|company|company_notes"><?=nl2br($company->company_notes);?></span>
			</p>

		</div>
</div>
<?php endif;?>



<?php if ($company->prospect):?>
	<div class="block">
		<div class="hd">
			<h2>Prospect Overview</h2>
		</div>
		<div class="bd">
			<ul class="companyDetails">
				<li>Pitch Review Date<span class="<?php if ($permissions->editcompanydetails):?>edit_dateinput<?php endif;?>" id="<?=$company->id;?>|company|pitchreviewdate"><?php if ($company->pitchreviewdate):?><?= date("d/m/Y", strtotime($company->pitchreviewdate)); ?><?php endif;?></span>
				</li>
				<li>Annual Marketing Spend<span class="<?php if ($permissions->editcompanydetails):?>edit_textinput<?php endif;?>" id="<?=$company->id;?>|company|marketingspend"><?=$company->marketingspend;?></span>
				</li>
				<li>Current Agencies<span class="<?php if ($permissions->editcompanydetails):?>edit_textarea<?php endif;?>" id="<?=$company->id;?>|company|currentagency"><?=nl2br($company->currentagency);?></span>
				</li>
			</ul>
		</div>
	</div>
<?php endif;?>



<?php if ($supplieron):?>
	<div class="block">
		<div class="hd">
			<h2>Currently Working On</h2>
		</div>
		<div class="bd">
			<table>
				<thead>
				<tr>
					<th>Code and Name</th>
					<th>Status</th>
				</tr>
				</thead>
				<tbody>
				<?php foreach ($supplieron as $job):?>
				<tr>
					<td>
						<?=$job->cost_title;?> on <a href="<?=site_url('company/'.$job->company_name.'/'.$job->job_title);?>"><?=$job->job_title;?></a> <small><?=$job->job_number;?></small> for <a href="<?=site_url('company/'.$job->company_name);?>"><?=$job->company_name;?></a>
					</td>
					<td><?=ucfirst($job->job_status);?></td>
				</tr>
				<?php endforeach;?>
				</tbody>
			</table>
		</div>
	</div>
<?php endif;?>


<?php if ($permissions->changecompanystatus):?>

	<div class="block">
		<div class="hd">
			<h2>Company Status</h2>
		</div>
		<div class="bd">
	<?php if ($company->archived):?>
		<?=form_open('companies/changestatus/'.$company->id);?>
			<input type="hidden" name="companyid" value="<?=$company->id;?>" />
			<input type="hidden" name="unarchived" value="1" />
			<input type="submit" class="" name="submit" value="Unarchive" />
		<?=form_close();?>
	<?php else:?>
		<?=form_open('companies/changestatus/'.$company->id);?>
			<input type="hidden" name="companyid" value="<?=$company->id;?>" />
			<input type="hidden" name="archived" value="1" />
			<input type="submit" class="" name="submit" value="Archive" />
		<?=form_close();?>
	<?php endif;?>

	<?php if (!$company->supplier && !$company->prospect && $company->client):?>
		 <?=form_open('companies/changestatus/'.$company->id);?>
			<input type="hidden" name="companyid" value="<?=$company->id;?>" />
			<input type="hidden" name="prospect" value="1" />
			<input type="submit" class="" name="submit" value="Make Prospect" />
		<?=form_close();?>
	<?php endif;?>

	<?php if ($company->prospect):?>
		<?=form_open('companies/changestatus/'.$company->id);?>
			<input type="hidden" name="companyid" value="<?=$company->id;?>" />
			<input type="hidden" name="client" value="1" />
			<input type="submit" class="" name="submit" value="Make Client" />
		<?=form_close();?>
	<?php endif;?>

	<?php if (!$company->supplier):?>
		 <?=form_open('companies/changestatus/'.$company->id);?>
			<input type="hidden" name="companyid" value="<?=$company->id;?>" />
			<input type="hidden" name="supplier" value="1" />
			<input type="submit" class="" name="submit" value="Make Supplier" />
		<?=form_close();?>
	<?php endif;?>

	<?php if ($company->supplier && !$supplieron):?>
		 <?=form_open('companies/changestatus/'.$company->id);?>
			<input type="hidden" name="companyid" value="<?=$company->id;?>" />
			<input type="hidden" name="supplier" value="0" />
			<input type="submit" class="" name="submit" value="Not a Supplier" />
		<?=form_close();?>
	<?php endif;?>
	
	<?php if ($company->supplier && $company->client && !$activejobs && !$proposedjobs && !$completedjobs && !$archivedjobs):?>
		 <?=form_open('companies/changestatus/'.$company->id);?>
			<input type="hidden" name="companyid" value="<?=$company->id;?>" />
			<input type="hidden" name="client" value="0" />
			<input type="submit" class="" name="submit" value="Not a Client" />
		<?=form_close();?>
	<?php endif;?>
	
	<?php if ($company->supplier && $company->prospect && !$activejobs && !$proposedjobs && !$completedjobs && !$archivedjobs):?>
		 <?=form_open('companies/changestatus/'.$company->id);?>
			<input type="hidden" name="companyid" value="<?=$company->id;?>" />
			<input type="hidden" name="prospect" value="0" />
			<input type="submit" class="" name="submit" value="Not a Prospect" />
		<?=form_close();?>
	<?php endif;?>

	<?php if ($company->supplier && !$company->prospect && !$company->client):?>
		<?=form_open('companies/changestatus/'.$company->id);?>
			<input type="hidden" name="companyid" value="<?=$company->id;?>" />
			<input type="hidden" name="prospect" value="1" />
			<input type="submit" class="" name="submit" value="Make Prospect" />
		<?=form_close();?>
		<?=form_open('companies/changestatus/'.$company->id);?>
			<input type="hidden" name="companyid" value="<?=$company->id;?>" />
			<input type="hidden" name="client" value="1" />
			<input type="submit" class="" name="submit" value="Make Client" />
		<?=form_close();?>
	<?php endif;?>
		</div>
	</div>
<?php endif;?>

